!function () {

	var $ = window.jQuery

	$(function () {
		alert('资源管理器');

		resizeFrame();
		window.addEventListener('resize', resizeFrame);

		console.log($('#header').width());
		console.log($('#header').height());

		var options = {
			showTags: true,
			levels: 10,
			data: buildDomTree()
		};


		$('.tree-list .icon').click(function () {
			$(this).parent().children('ul').toggle(100);
		});
	
		// $('#treeview').treeview(options);
	});

	function resizeFrame() {
		var height = $('body').height();
		height -= $('#header').height();
		height -= $('#footer').height();
		$('#frame').height(height);
	}

	function buildDomTree() {

        var data = [{
			id: 'root',
			text: '根目录'
		}];

        function walk(nodes, data) {
			if (!nodes) { return; }
			$.each(nodes, function (id, node) {
				var obj = {
					id: id,
					text: node.nodeName + " - " + (node.innerText ? node.innerText : ''),
					tags: [node.childElementCount > 0 ? node.childElementCount : '']
				};
				if (node.childElementCount > 0) {
					obj.nodes = [];
					walk(node.children, obj.nodes);
				}
				data.push(obj);
			});
        }
        walk($('#main_frame')[0].children, data);

        return data;
	}

} ();